package com.wjr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wjr.model.User;
import com.wjr.utils.DBUtil;

public class UserDao {
	private static Connection conn = null;
	PreparedStatement stmt = null;
	
	public User login(User user) throws SQLException {
		conn=DBUtil.getconnection();
		stmt = conn.prepareStatement("select username,password from user WHERE username=? and password=?");
		stmt.setString(1, user.getUsername());
		stmt.setString(2, user.getPassword());
		ResultSet rs = stmt.executeQuery();
		
		User newUser = null;
		
		if(rs.next()){
			newUser = new User();
			newUser.setUsername(rs.getString("username"));
			newUser.setPassword(rs.getString("password"));
		}
		DBUtil.closeConn(conn);
		
		return newUser;
	}
	
	
}

